﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace mas_apredizaje
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        clases.cuenta ct = new clases.cuenta();
        clases.Alumno alm = new clases.Alumno();

        private void login_Load(object sender, EventArgs e)
        {
            textrut.Focus();
        }
        
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            string rut=textrut.Text, pass=textpass.Text;
            if (textrut.Text == string.Empty || textrut.Text.Trim() == "" /*|| textpass.Text == string.Empty || textpass.Text.Trim() == ""*/)
            {
                MessageBox.Show("campo vacios");
            }
            else
            {
                textrut.Text = textrut.Text.Trim();
                textrut.Text = Regex.Replace(textrut.Text, @"\s+", " ");
                textpass.Text = textpass.Text.Trim();
                textpass.Text = Regex.Replace(textpass.Text, @"\s+", " ");

             
              if (checkprof.Checked == true)
                {
                    DataSet d1 = new BD.controllogin().inicioprof(textpass.Text, textrut.Text);
                    if (d1.Tables["prof"].Rows.Count == 0)
                    {
                        MessageBox.Show("error usuario o contraseña");
                    }
                    else
                    {   
                        menuProf fmr = new menuProf();                                              
                        fmr.Show();
                        this.Hide();                        
                        fmr.rut(textrut.Text);
                    }
                }
                else
                {
                    DataSet d1 = new BD.controllogin().inicioalum(textrut.Text);
                    if (d1.Tables["alum"].Rows.Count == 0)
                    {
                        MessageBox.Show("usuario no existe");                        
                    }
                    else
                    {
                        string nomb = d1.Tables["alum"].Rows[0][1].ToString();
                          
                        alm.rut = textrut.Text;
                        menuAlum fmr = new menuAlum();
                        fmr.nombre(nomb);
                        fmr.Show();                        
                        this.Hide();
                       // MessageBox.Show(""+nomb); 
                        
                    }
                }
            }
        }

        private void login_Load_1(object sender, EventArgs e)
        {
            textpass.Enabled = false;
        }

        private void check(object sender, EventArgs e)
        {
            if (checkprof.Checked.Equals(Enabled))
            {
                textpass.Enabled = true;
                textpass.Text = "";
            }
            else {
                textpass.Enabled = false;
                textpass.Text = "";
            }
        }
    }
}
